package business;

import entity.Event;
import entity.User;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class EventManager {
    
    @PersistenceContext
    private EntityManager entityManager;
    
    public void create(Event event) {
        entityManager.persist(event);
    }
    
    public void save(Event event) {
        entityManager.merge(event);
    }
    
    public Event find(int eventId) {
        return entityManager.find(Event.class, eventId);
    }

    public void delete(Event event) {
        entityManager.remove(entityManager.find(Event.class, event.getEventId()));
    }
    
    public boolean exists(int eventId) {
        return entityManager.find(Event.class, eventId) != null;
    }
}
